<template>
	<view class="container">
		<view class="list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">微信收款码</text>
			<image class="head_img" :src="avatarw || '/static/shangchuan.png'" @tap="uploadTap(2)"></image>
		</view>
		<view class="list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">支付宝收款码</text>
			<image class="head_img" :src="avatarz || '/static/shangchuan.png'" @tap="uploadTap(1)"></image>
		</view>
	</view>
	
</template>

<script>
	import {  
	    mapMutations, mapActions, mapState
	} from 'vuex';
	export default {
		data() {
			return {
				tempFilePaths: "",
				avatarw:'',
				avatarz:''
			};
		},
		computed: {
			...mapState({
				userinfo: state => state.user.userinfo
			}),
			hasLogin() {
				return this.userinfo.id ? true : false
			}
		},
		onLoad(option) {
			this.initDat();//初始化数据
		},
		methods:{
			...mapMutations(['SAVE_USERINFO']),
			uploadTap(status) {
				let that = this
				uni.chooseImage({
				  count: 1, //默认9
				  sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				  sourceType: ['album'],
				  success: (chooseImageRes) => {
				    that.tempFilePaths = chooseImageRes.tempFilePaths;
				    uni.uploadFile({
				      url: this.$common.baseUrl + '/api/common/upload', //上传接口地址
				      filePath: that.tempFilePaths[0],
				      name: 'file',
				      enctype: "multipart/form-data",
				      formData: {
				        mobile: that.phone
				      },
				        success: (uploadFileRes) => {
							let res = JSON.parse(uploadFileRes.data);
							if(status == 1){
								that.avatarz = this.$common.baseUrl + res.data.url;
							}else{
								that.avatarw = this.$common.baseUrl + res.data.url;
							}
							this.$http.post('updatema',{shouqianma: res.data.url, status: status}).then(res => {
								this.$api.msg(res.msg);
							})
							
						}
				    });
				
				  }
				});
		},
		//初始化数据
		initDat(){
			this.$http.post('shezhiuserinfo').then(res => {
				if(res.data.wei_image){
					this.avatarw = this.$common.baseUrl + res.data.wei_image;
				}
				if(res.data.zhi_image){
					this.avatarz = this.$common.baseUrl + res.data.zhi_image;
				}			
			})
		}
	},
	}
</script>

<style lang='scss'>
	page{
		background: $page-color-base;
	}
	.list-cell{
		display:flex;
		align-items:baseline;
		padding: 20upx $page-row-spacing;
		line-height:60upx;
		position:relative;
		background: #fff;
		justify-content: center;
		align-items: center;
		&.log-out-btn{
			margin-top: 40upx;
			.cell-tit{
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}
		}
		&.cell-hover{
			background:#fafafa;
		}
		&.b-b:after{
			left: 30upx;
		}
		.cell-tit{
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right:10upx;
		}
	}
	.head_img{
		width: 90upx;
		height: 90upx;
		border-radius: 50%;
	}
</style>
